#include "../arduinomega/radio/radio.h"
#include "../arduinomega/radio/packet.h"
#include "../arduinomega/WProgram.h"
#include "../arduinomega/HardwareSerial.h"

/* Radio		Seeeduino
 *  Vcc				48
 *   CE				49
 *  CSN				47
 *  SCK				52
 * MOSI				51
 * MISO				50
 *  IRQ				2
 *  GND				GND*/
//uint8_t tx_addr[RADIO_ADDRESS_LENGTH] = { 0x05, 0x04, 0x03, 0x02, 0x01 };//hovercraft address
uint8_t rx_addr[RADIO_ADDRESS_LENGTH] = { 0x01, 0x02, 0x03, 0x04, 0x05 };//remote joystick address
uint8_t tx_addr[RADIO_ADDRESS_LENGTH] = { 0x98, 0x76, 0x54, 0x32, 0x10 };//debug station

radiopacket_t packet;
const int MESSAGE_ID = 41;

unsigned long testPotentiometerReading;

extern "C" void __cxa_pure_virtual(){};

int main(){
	init();
	Serial.begin( BAUD_RATE );
	Serial.println("Configured Radio Transmitter");

	// Blink the LED once to indicate that the program has started (this step is useless).
	pinMode(13, OUTPUT);
	digitalWrite(13, HIGH);
	delay(1000);
	digitalWrite(13, LOW);
	delay(1000);

	pinMode(48, OUTPUT);
	digitalWrite(48, HIGH);//turn radio on
	Serial.println( "Initializing radio..." );
	Radio_Init();
	Serial.println( "Radio Initialized" );


	Radio_Configure_Rx(RADIO_PIPE_0, rx_addr, ENABLE);
	Radio_Configure(RADIO_2MBPS, RADIO_HIGHEST_POWER);

	Radio_Set_Tx_Addr( tx_addr );


	packet.type = MESSAGE;

	memcpy(packet.payload.message.address, rx_addr, RADIO_ADDRESS_LENGTH);
	packet.payload.message.messageid = MESSAGE_ID;

	snprintf((char*)packet.payload.message.messagecontent, 20, "Full Duty");
	Serial.println( "transmitting first packet..." );
	Radio_Transmit(&packet, RADIO_WAIT_FOR_TX);
	Serial.println( "first packet transmitted" );

	snprintf((char*)packet.payload.message.messagecontent, 20, "Half duty");
	Radio_Transmit(&packet, RADIO_WAIT_FOR_TX);

	snprintf((char*)packet.payload.message.messagecontent, 20, "Off Duty");
	Radio_Transmit(&packet, RADIO_WAIT_FOR_TX);

	for (;;)
	{
		digitalWrite(13, LOW);
		delay(200);
		digitalWrite(13, HIGH);
		delay(200);
	}

	return 0;

return 0;
}
